﻿using YNTK.Common.Enum;
using YNTK.Dependency;

namespace YNTK.Common.Filter
{
    /// <summary>
    /// 通用结果返回
    /// </summary>
    [SuppressSniffer]
    public class TkResult
    {
        /// <summary>
        /// 返回消息
        /// </summary>
        public string message { get; set; }

        /// <summary>
        /// 对象类型
        /// </summary>
        public ResultTypeEnum resultType { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public TkResult()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="resultType">返回类型</param>
        /// <param name="message">返回消息</param>
        public TkResult(ResultTypeEnum resultType, string message = "")
        {
            this.resultType = resultType;
            this.message = message;
        }

        /// <summary>
        /// 获得一个成功返回对象
        /// </summary>
        /// <param name="message">返回消息</param>
        /// <returns>成功返回对象</returns>
        public static TkResult Success(string message = "")
        {
            return new TkResult(ResultTypeEnum.Success, message);
        }

        /// <summary>
        /// 获得一个失败返回对象
        /// </summary>
        /// <param name="message">返回消息</param>
        /// <returns>失败返回对象</returns>
        public static TkResult Fail(string message = "")
        {
            return new TkResult(ResultTypeEnum.Fail, message);
        }

    }

    /// <summary>
    /// 通用结果返回
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class TkResult<T> : TkResult
    {
        /// <summary>
        /// 返回数据
        /// </summary>
        public T data { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public TkResult()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="resultType">返回类型</param>
        /// <param name="data">返回数据对象</param>
        /// <param name="message">返回消息</param>
        public TkResult(ResultTypeEnum resultType, T data, string message = "") : base(resultType, message)
        {
            this.data = data;
        }

        /// <summary>
        /// 获得一个成功返回对象
        /// </summary>
        /// <param name="data">返回数据对象</param>
        /// <param name="message">返回消息</param>
        /// <returns>成功返回对象</returns>
        public static TkResult<T> Success(T data, string message = "")
        {
            return new TkResult<T>(ResultTypeEnum.Success, data, message);
        }

        /// <summary>
        /// 获得一个成功返回对象
        /// </summary>
        /// <param name="message">返回消息</param>
        /// <returns>成功返回对象</returns>
        public new static TkResult<T> Success(string message = "")
        {
            return new TkResult<T>(ResultTypeEnum.Success, default(T), message);
        }

        /// <summary>
        /// 获得一个失败返回对象
        /// </summary>
        /// <param name="data">返回数据对象</param>
        /// <param name="message">返回消息</param>
        /// <returns>失败返回对象</returns>
        public static TkResult<T> Fail(T data, string message = "")
        {
            return new TkResult<T>(ResultTypeEnum.Fail, data, message);
        }

        /// <summary>
        /// 获得一个失败返回对象
        /// </summary>
        /// <param name="message">返回消息</param>
        /// <returns>失败返回对象</returns>
        public new static TkResult<T> Fail(string message = "")
        {
            return new TkResult<T>(ResultTypeEnum.Fail, default(T), message);
        }
    }

}
